package com.goods.controller.business;

import com.goods.business.service.ProductService;
import com.goods.common.model.business.Product;
import com.goods.common.model.business.ProductCategory;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ProductCategoryTreeNodeVO;
import com.goods.common.vo.business.ProductCategoryVO;
import com.goods.common.vo.business.ProductVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**********************
 *
 *@Author 闫星忠
 *@Time 2021/12/16  9:48
 *
 */
@Api(tags = "业务模块-物资资料相关接口")
@RestController
@RequestMapping("/business/product")
public class ProductController {


    @Autowired
    private ProductService productService;

    @ApiOperation(value = "物资资料分页列表展示")
    @GetMapping("/findProductList")
    public ResponseBean<PageVO<ProductVO>> findProductList(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize") Integer pageSize,
            @RequestParam(value = "categorys" ) String categoryKeys,
            ProductVO productVO) {
        PageVO<ProductVO> productList = productService.findProductList(pageNum, pageSize,categoryKeys,productVO);
        return ResponseBean.success(productList);
    }

    @ApiOperation(value = "添加物资资料")
    @PostMapping("/add")
    public ResponseBean add(@RequestBody ProductVO productVO){
        productService.add(productVO);

        return ResponseBean.success();
    }

    @ApiOperation(value = "编辑页，数据回显")
    @GetMapping("/edit/{id}")
    public ResponseBean<ProductVO> edit(@PathVariable Long id){
        ProductVO productVO = productService.edit(id);
        return ResponseBean.success(productVO);
    }

    @ApiOperation(value = "编辑页，数据提交，修改物资资料")
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id ,@RequestBody ProductVO productVO){
        productService.update(id,productVO);
        return ResponseBean.success();
    }


    @ApiOperation(value = "移入回收站")
    @PutMapping("/remove/{id}")
    public ResponseBean remove(@PathVariable Long id){
        productService.remove(id);
        return ResponseBean.success();
    }

    @ApiOperation(value = "移出回收站到正常")
    @PutMapping ("/back/{id}")
    public ResponseBean back(@PathVariable Long id){
        productService.back(id);
        return ResponseBean.success();
    }

    @ApiOperation(value = "从回收站删除物资资料")
    @DeleteMapping("/delete/{id}")
    public ResponseBean update(@PathVariable Long id){
        productService.delete(id);
        return ResponseBean.success();
    }

    @ApiOperation(value = "待审核转到正常")
    @PutMapping ("/publish/{id}")
    public ResponseBean publish(@PathVariable Long id){
        productService.publish(id);
        return ResponseBean.success();
    }




}
